﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace MyVisualWebPart.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        private static SPWeb web;
        private static SPList list;
        private static SPQuery query;
        private static ListViewByQuery lvbq;

        private void getPanelClosed()
        {
            panel_kunde.Visible = false;
            panel_projekte.Visible = false;
            panel_produkte.Visible = false;
            panel_prozess.Visible = false;
            panel_dok.Visible = false;
        }

        private void getImageClosed()
        {
            getImageMainDoorClosed();
            getImageKundeClosed();
            getImageProdukteClosed();
            getImageProjekteClosed();
            getImageProzesseClosed();
            getImageDokumentKategorieClosed();
        }

        private void getImageMainDoorClosed()
        {
            btn_kunden.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_kunden_grau.png";
            btn_produkte.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_grau.png";
            btn_prozesse.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_grau.png";
            btn_projekte.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_grau.png";
        }

        private void getImageKundeClosed()
        {
            img_kunde_Anlagenbau.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_kunden_anlagenbau.png";
            img_kunde_Elektroteknik.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_kunden_elektrotechnik.png";
            img_kunde_Maschinenbau.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_kunden_maschinenbau.png";
        }

        private void getImageProzesseClosed()
        {
            img_prozess_management.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_management.png";
            img_prozess_produktions.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_produktion.png";
            img_prozess_marketing.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_marketing.png";
            img_prozess_support.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_support.png";
            img_prozess_vertrieb.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_vertrieb.png";
        }

        private void getImageProdukteClosed()
        {
            img_produkt1.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_kat1.png";
            img_produkt2.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_kat2.png";
            img_produkt3.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_kat3.png";
            img_produkt4.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_kat4.png";

        }

        private void getImageProjekteClosed()
        {
            img_projekt_121.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_121.png";
            img_projekt_123.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_123.png";
            img_projekt_154.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_154.png";
            img_projekt_156.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_156.png";
            img_projekt_188.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_188.png";
            img_projekt_189.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_189.png";
        }

        private void getImageDokumentKategorieClosed()
        {
            img_marketingdok.ImageUrl = "~/_layouts/images/MyVisualWebPart/marketingdoku.png";
            img_geschaftdok.ImageUrl = "~/_layouts/images/MyVisualWebPart/geschäftdoku.png";
            img_produktionsdok.ImageUrl = "~/_layouts/images/MyVisualWebPart/produktionsdoku.png";
            img_projektdoku.ImageUrl = "~/_layouts/images/MyVisualWebPart/projektdoku.png";
        }

        public static void Initializer()
        {
            web = SPContext.Current.Web;
            //string loginname = web.CurrentUser.LoginName;
            //string username = web.CurrentUser.Name;
            list = web.Lists["Testbibliothek_Managed_Metadata"];
            lvbq = new ListViewByQuery();
            //lvbq.EnableViewState = false;
            lvbq.List = list;
            query = new SPQuery(list.Views["NameAnsicht"]);

        }



        #region Event Handler

        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {

            if (btn_viewdoor.ImageUrl == "~/_layouts/images/MyVisualWebPart/viewdoorskachel_grau.png")
            {
                btn_viewdoor.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_grau_auf.png";
                btn_kunden.Visible = true;
                btn_produkte.Visible = true;
                btn_projekte.Visible = true;
                btn_prozesse.Visible = true;
            }
            else
            {
                getImageClosed();
                getPanelClosed();
                btn_viewdoor.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_grau.png";
                btn_kunden.Visible = false;
                btn_produkte.Visible = false;
                btn_projekte.Visible = false;
                btn_prozesse.Visible = false;
            }
        }

        protected void btn_kunden_Click(object sender, ImageClickEventArgs e)
        {

            getImageClosed();
            getPanelClosed();
            getImageKundeClosed();
            btn_kunden.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_kunden_auf.png";
            panel_kunde.Visible = true;
            Initializer();
            string myQuery = null;
            myQuery = "<Where><IsNotNull><FieldRef Name='Kunde'/></IsNotNull></Where>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }


        protected void btn_produkte_Enter(object sender, EventArgs e)
        {
            btn_prozesse.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte.png";
        }

        protected void btn_produkte_Out(object sender, EventArgs e)
        {
            btn_prozesse.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_grau.png";
        }

        protected void btn_produkte_Click(object sender, ImageClickEventArgs e)
        {
            getImageClosed();
            getPanelClosed();
            getImageProdukteClosed();
            btn_produkte.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_auf.png";
            panel_produkte.Visible = true;
            Initializer();
            string myQuery = null;
            myQuery = " <Where><And> <IsNotNull> <FieldRef Name='Produktgruppe' /> </IsNotNull> <IsNotNull> <FieldRef Name='Produktkategorie' /></IsNotNull></And></Where>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }



        protected void btn_prozesse_Click(object sender, ImageClickEventArgs e)
        {
            getImageClosed();
            getPanelClosed();
            getImageProzesseClosed();
            btn_prozesse.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_auf.png";
            panel_prozess.Visible = true;
            Initializer();
            string myQuery = null;
            myQuery = "<Where><IsNotNull><FieldRef Name='Prozess'/></IsNotNull></Where>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void btn_projekte_Click(object sender, ImageClickEventArgs e)
        {
            getImageClosed();
            getPanelClosed();
            getImageProjekteClosed();
            btn_projekte.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_auf.png";
            panel_projekte.Visible = true;
            Initializer();
            string myQuery = null;
            myQuery = "<Where><IsNotNull><FieldRef Name='Projektnummer' /></IsNotNull></Where>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }



        protected void img_produktA_Click(object sender, ImageClickEventArgs e)
        {
            getImageProdukteClosed();
            img_produkt1.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_auf_kat1.png";
            panel_dok.Visible = true;
            Initializer();
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Produktgruppe' /></IsNotNull><Eq><FieldRef Name='Produktgruppe' /><Value Type='Choice'>Produktgruppe A</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);

        }

        protected void img_produktB_Click(object sender, ImageClickEventArgs e)
        {
            getImageProdukteClosed();
            img_produkt2.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_auf_kat2.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Produktgruppe' /></IsNotNull><Eq><FieldRef Name='Produktgruppe' /><Value Type='Choice'>Produktgruppe B</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void img_produktC_Click(object sender, ImageClickEventArgs e)
        {
            getImageProdukteClosed();
            img_produkt3.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_auf_kat3.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Produktgruppe' /></IsNotNull><Eq><FieldRef Name='Produktgruppe' /><Value Type='Choice'>Produktgruppe C</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void img_produktD_Click(object sender, ImageClickEventArgs e)
        {
            getImageProdukteClosed();
            img_produkt4.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_produkte_auf_kat4.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Produktgruppe' /></IsNotNull><Eq><FieldRef Name='Produktgruppe' /><Value Type='Choice'>Produktgruppe D</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }


        protected void img_kunde_Elektroteknik_Click(object sender, ImageClickEventArgs e)
        {
            getImageKundeClosed();
            img_kunde_Elektroteknik.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_kunden_auf_elektrotechnik.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><Eq><FieldRef Name='Kunde' /><Value Type='Choice'>Firma Elektrotechnik</Value></Eq></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void img_kunde_Maschinenbau_Click(object sender, ImageClickEventArgs e)
        {
            getImageKundeClosed();
            img_kunde_Maschinenbau.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_kunden_auf_maschinenbau.png";
            panel_dok.Visible = true;
            Initializer();
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Kunde' /></IsNotNull><Eq><FieldRef Name='Kunde' /><Value Type='Choice'>Firma Maschinenbau</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void img_kunde_Anlagenbau_Click(object sender, ImageClickEventArgs e)
        {
            getImageKundeClosed();
            img_kunde_Anlagenbau.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_kunden_auf_Anlagenbau.png";
            panel_dok.Visible = true;
            Initializer();
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Kunde' /></IsNotNull><Eq><FieldRef Name='Kunde' /><Value Type='Choice'>Firma Anlagenbau</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }




        protected void img_projekt123_Click(object sender, ImageClickEventArgs e)
        {
            getImageProjekteClosed();
            img_projekt_123.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_auf_123.png";
            panel_dok.Visible = true;
            Initializer();
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Projektnummer' /></IsNotNull><Eq><FieldRef Name='Projektnummer' /><Value Type='Number'>123</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void Img_Projekt_121_Click(object sender, ImageClickEventArgs e)
        {
            getImageProjekteClosed();
            img_projekt_121.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_auf_121.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Projektnummer' /></IsNotNull><Eq><FieldRef Name='Projektnummer' /><Value Type='Number'>121</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void Img_Projekt_154_Click(object sender, ImageClickEventArgs e)
        {
            getImageProjekteClosed();
            img_projekt_154.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_auf_154.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Projektnummer' /></IsNotNull><Eq><FieldRef Name='Projektnummer' /><Value Type='Number'>154</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }


        protected void Img_Projekt_156_Click(object sender, ImageClickEventArgs e)
        {
            getImageProjekteClosed();
            img_projekt_156.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_auf_156.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Projektnummer' /></IsNotNull><Eq><FieldRef Name='Projektnummer' /><Value Type='Number'>156</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void Img_Projekt_188_Click(object sender, ImageClickEventArgs e)
        {
            getImageProjekteClosed();
            img_projekt_188.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_auf_188.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Projektnummer' /></IsNotNull><Eq><FieldRef Name='Projektnummer' /><Value Type='Number'>188</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void Img_Projekt_189_Click(object sender, ImageClickEventArgs e)
        {
            getImageProjekteClosed();
            img_projekt_189.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_projekte_auf_189.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = "<Query><Where><And><IsNotNull><FieldRef Name='Projektnummer' /></IsNotNull><Eq><FieldRef Name='Projektnummer' /><Value Type='Number'>189</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void img_management_Click(object sender, ImageClickEventArgs e)
        {
            getImageProzesseClosed();
            img_prozess_management.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_auf_management.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = " <Query><Where><And><IsNotNull><FieldRef Name='Prozess' /></IsNotNull><Eq><FieldRef Name='Prozess' /><Value Type='Text'>management</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void img_prozess_marketing_Click(object sender, ImageClickEventArgs e)
        {
            getImageProzesseClosed();
            img_prozess_marketing.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_auf_marketing.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = " <Query><Where><And><IsNotNull><FieldRef Name='Prozess' /></IsNotNull><Eq><FieldRef Name='Prozess' /><Value Type='Text'>marketing</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }


        protected void img_prozess_support_Click(object sender, ImageClickEventArgs e)
        {
            getImageProzesseClosed();
            img_prozess_support.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_auf_support.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = " <Query><Where><And><IsNotNull><FieldRef Name='Prozess' /></IsNotNull><Eq><FieldRef Name='Prozess' /><Value Type='Text'>support</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void img_prozess_vertrieb_Click(object sender, ImageClickEventArgs e)
        {
            getImageProzesseClosed();
            img_prozess_vertrieb.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_auf_vertrieb.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = " <Query><Where><And><IsNotNull><FieldRef Name='Prozess' /></IsNotNull><Eq><FieldRef Name='Prozess' /><Value Type='Text'>vertrieb</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }

        protected void img_prozess_produktions_Click(object sender, ImageClickEventArgs e)
        {
            getImageProzesseClosed();
            img_prozess_produktions.ImageUrl = "~/_layouts/images/MyVisualWebPart/viewdoorskachel_prozesse_auf_produktion.png";
            Initializer();
            panel_dok.Visible = true;
            string myQuery = null;
            myQuery = " <Query><Where><And><IsNotNull><FieldRef Name='Prozess' /></IsNotNull><Eq><FieldRef Name='Prozess' /><Value Type='Text'>produktion</Value></Eq></And></Where></Query>";
            query.Query = myQuery;
            lvbq.Query = query;
            this.Controls.Add(lvbq);
        }


        #endregion




    }
}